import { mapGetters } from 'vuex'

export const enumPayStatus = {
  0: '未缴费 ',
  1: '已缴费 ',
  2: '已到账 ',
  3: '提前缴费',
}

export const enumPayStatusStyle = {
  0: 'info',
  1: 'primary',
  2: 'success',
  3: 'success',
}

export const enumSettleArrivalStatus = {
  1: '待查实',
  2: '已到账',
}

export default {
  data() {
    return {
      params: {},
      order: {},
      loading: false,
      tableName: 'credit_warrant_fee_record_view_db',
      tableData: [],
      totalCount: 0,
    }
  },
  props: {
    guaType: {
      type: Number,
      default: 1,
    },
  },
  computed: {
    ...mapGetters(['clientId', 'user', 'job']),
    isUserCity() {
      return this.user.orgRegionLever < 3
    },
    isUnionCity() {
      return this.guaType === 1 && this.isUserCity
    },
    // 业务部
    isUserBusiness() {
      return ['org_c_manage', 'org_c_emp'].includes(this.job)
    },
    // 账务部
    isUserAccount() {
      return ['org_f_manage', 'org_f_emp'].includes(this.job)
    },
    userParams() {
      const params = {}
      if (this.guaType === 1) {
        params['gua_type.in'] = '1,4'
      } else {
        params['gua_type.eq'] = this.guaType
      }

      params['service_id.eq'] = this.clientId
      return params
    },
  },
  created() {
    this.getData()
  },
  methods: {
    async getData(index = 1) {
      this.params.index = index
      this.loading = true
      const [res] = await this.$utils.promise(
        this.$api.getData(this.$serviceName, this.tableName, this.getParams(), this.order)
      )
      this.loading = false

      const data = (res && res.data) || {}
      this.totalCount = data.totalCount || 0
      this.tableData = (data.data || []).map(this.dataAdapter)
    },
    getParams() {
      return {
        ...this.params,
        ...this.userParams,
      }
    },
    dataAdapter(row) {
      return row
    },
  },
}
